<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title></title>
</head>
<body>
  <div id="root"></div>
  <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script src="https://unpkg.com/prop-types@15.6/prop-types.js"></script>
  <script type="text/babel">

    class Form extends React.Component{

      state = {
        username: "",
        password: ""
      }

      handleSubmit = (event)=>{
        event.preventDefault()
        console.log(this.state)
      }

      handleDataChange = (e)=>{
        this.setState({
          [e.target.name]: e.target.value
        })
      }

      render(){
        return (
          <form onSubmit={this.handleSubmit}>
            <input name="username" onChange={this.handleDataChange} />
            <input name="password" onChange={this.handleDataChange} />
            <button>提交</button>
          </form>
        )
      }
    }

    ReactDOM.render(<Form />,document.getElementById("root"))
  </script>
</body>
</html>